function [residual, g1, g2, g3] = a15_markups_cbase_dynamic(y, x, params, steady_state, it_)
%
% Status : Computes dynamic model for Dynare
%
% Inputs :
%   y         [#dynamic variables by 1] double    vector of endogenous variables in the order stored
%                                                 in M_.lead_lag_incidence; see the Manual
%   x         [M_.exo_nbr by nperiods] double     matrix of exogenous variables (in declaration order)
%                                                 for all simulation periods
%   params    [M_.param_nbr by 1] double          vector of parameter values in declaration order
%   it_       scalar double                       time period for exogenous variables for which to evaluate the model
%
% Outputs:
%   residual  [M_.endo_nbr by 1] double    vector of residuals of the dynamic model equations in order of 
%                                          declaration of the equations
%   g1        [M_.endo_nbr by #dynamic variables] double    Jacobian matrix of the dynamic model equations;
%                                                           rows: equations in order of declaration
%                                                           columns: variables in order stored in M_.lead_lag_incidence
%   g2        [M_.endo_nbr by (#dynamic variables)^2] double   Hessian matrix of the dynamic model equations;
%                                                              rows: equations in order of declaration
%                                                              columns: variables in order stored in M_.lead_lag_incidence
%   g3        [M_.endo_nbr by (#dynamic variables)^3] double   Third order derivative matrix of the dynamic model equations;
%                                                              rows: equations in order of declaration
%                                                              columns: variables in order stored in M_.lead_lag_incidence
%
%
% Warning : this file is generated automatically by Dynare
%           from model file (.mod)

%
% Model equations
%

residual = zeros(18, 1);
T80 = params(1)*exp(y(29))*exp(y(27)-y(10))^2*y(32);
T140 = exp((-y(31))-1/params(12));
T141 = params(5)*exp(y(25)-y(7)+y(17))*T140;
lhs =y(18);
rhs =params(16)/2*(exp(y(10)-y(3))-1)^2;
residual(1)= lhs-rhs;
lhs =y(19);
rhs =params(16)*(exp(y(10)-y(3))-1);
residual(2)= lhs-rhs;
lhs =y(21);
rhs =y(25)-y(7);
residual(3)= lhs-rhs;
lhs =y(17);
rhs =log(params(1))+y(28)-y(12);
residual(4)= lhs-rhs;
lhs =exp(y(12));
rhs =(exp(y(8))-params(17)*exp(y(1)))^(-params(8))-params(1)*params(17)*(exp(y(26))-exp(y(8))*params(17))^(-params(8));
residual(5)= lhs-rhs;
lhs =params(9)*exp(y(11))^params(2);
rhs =exp(y(12))*exp(y(15));
residual(6)= lhs-rhs;
lhs =exp(y(12));
rhs =exp(y(13))*(1-y(18)-exp(y(10)-y(3))*y(19))+T80;
residual(7)= lhs-rhs;
lhs =exp(y(13));
rhs =params(1)*(exp(y(28))*exp(y(30))+exp(y(29))*(1-params(3)));
residual(8)= lhs-rhs;
lhs =(1-y(18))*exp(y(10));
rhs =exp(y(9))-(1-params(3))*exp(y(2));
residual(9)= lhs-rhs;
lhs =y(7);
rhs =y(22)+y(2)*params(4)+y(11)*(1-params(4));
residual(10)= lhs-rhs;
lhs =y(14);
rhs =y(7)+(-y(16))+log(params(4))-y(2);
residual(11)= lhs-rhs;
lhs =y(15);
rhs =y(7)+(-y(16))+log(1-params(4))-y(11);
residual(12)= lhs-rhs;
lhs =(1+params(13))*(exp((-y(16)))-1/params(12))-params(13)*(1-1/params(12));
rhs =T141;
residual(13)= lhs-rhs;
lhs =exp(y(8))+exp(y(10))+exp(y(20));
rhs =exp(y(7));
residual(14)= lhs-rhs;
lhs =y(20);
rhs =params(6)+y(23);
residual(15)= lhs-rhs;
lhs =y(22);
rhs =params(18)*y(4)+x(it_, 1);
residual(16)= lhs-rhs;
lhs =y(23);
rhs =x(it_, 2)+params(19)*y(5)+params(20)*y(6);
residual(17)= lhs-rhs;
lhs =y(24);
rhs =y(5);
residual(18)= lhs-rhs;
if nargout >= 2,
  g1 = zeros(18, 34);

  %
  % Jacobian matrix
  %

  g1(1,3)=(-(params(16)/2*(-exp(y(10)-y(3)))*2*(exp(y(10)-y(3))-1)));
  g1(1,10)=(-(params(16)/2*exp(y(10)-y(3))*2*(exp(y(10)-y(3))-1)));
  g1(1,18)=1;
  g1(2,3)=(-(params(16)*(-exp(y(10)-y(3)))));
  g1(2,10)=(-(params(16)*exp(y(10)-y(3))));
  g1(2,19)=1;
  g1(3,7)=1;
  g1(3,25)=(-1);
  g1(3,21)=1;
  g1(4,12)=1;
  g1(4,28)=(-1);
  g1(4,17)=1;
  g1(5,1)=(-((-(params(17)*exp(y(1))))*getPowerDeriv(exp(y(8))-params(17)*exp(y(1)),(-params(8)),1)));
  g1(5,8)=(-(exp(y(8))*getPowerDeriv(exp(y(8))-params(17)*exp(y(1)),(-params(8)),1)-params(1)*params(17)*(-(exp(y(8))*params(17)))*getPowerDeriv(exp(y(26))-exp(y(8))*params(17),(-params(8)),1)));
  g1(5,26)=params(1)*params(17)*exp(y(26))*getPowerDeriv(exp(y(26))-exp(y(8))*params(17),(-params(8)),1);
  g1(5,12)=exp(y(12));
  g1(6,11)=params(9)*exp(y(11))*getPowerDeriv(exp(y(11)),params(2),1);
  g1(6,12)=(-(exp(y(12))*exp(y(15))));
  g1(6,15)=(-(exp(y(12))*exp(y(15))));
  g1(7,3)=(-(exp(y(13))*(-(y(19)*(-exp(y(10)-y(3)))))));
  g1(7,10)=(-(exp(y(13))*(-(exp(y(10)-y(3))*y(19)))+y(32)*params(1)*exp(y(29))*(-exp(y(27)-y(10)))*2*exp(y(27)-y(10))));
  g1(7,27)=(-(y(32)*params(1)*exp(y(29))*exp(y(27)-y(10))*2*exp(y(27)-y(10))));
  g1(7,12)=exp(y(12));
  g1(7,13)=(-(exp(y(13))*(1-y(18)-exp(y(10)-y(3))*y(19))));
  g1(7,29)=(-T80);
  g1(7,18)=exp(y(13));
  g1(7,19)=(-(exp(y(13))*(-exp(y(10)-y(3)))));
  g1(7,32)=(-(params(1)*exp(y(29))*exp(y(27)-y(10))^2));
  g1(8,28)=(-(params(1)*exp(y(28))*exp(y(30))));
  g1(8,13)=exp(y(13));
  g1(8,29)=(-(params(1)*exp(y(29))*(1-params(3))));
  g1(8,30)=(-(params(1)*exp(y(28))*exp(y(30))));
  g1(9,2)=(1-params(3))*exp(y(2));
  g1(9,9)=(-exp(y(9)));
  g1(9,10)=(1-y(18))*exp(y(10));
  g1(9,18)=(-exp(y(10)));
  g1(10,7)=1;
  g1(10,2)=(-params(4));
  g1(10,11)=(-(1-params(4)));
  g1(10,22)=(-1);
  g1(11,7)=(-1);
  g1(11,2)=1;
  g1(11,14)=1;
  g1(11,16)=1;
  g1(12,7)=(-1);
  g1(12,11)=1;
  g1(12,15)=1;
  g1(12,16)=1;
  g1(13,7)=(-(T140*params(5)*(-exp(y(25)-y(7)+y(17)))));
  g1(13,25)=(-T141);
  g1(13,16)=(1+params(13))*(-exp((-y(16))));
  g1(13,31)=(-(params(5)*exp(y(25)-y(7)+y(17))*(-T140)));
  g1(13,17)=(-T141);
  g1(14,7)=(-exp(y(7)));
  g1(14,8)=exp(y(8));
  g1(14,10)=exp(y(10));
  g1(14,20)=exp(y(20));
  g1(15,20)=1;
  g1(15,23)=(-1);
  g1(16,4)=(-params(18));
  g1(16,22)=1;
  g1(16,33)=(-1);
  g1(17,5)=(-params(19));
  g1(17,23)=1;
  g1(17,34)=(-1);
  g1(17,6)=(-params(20));
  g1(18,5)=(-1);
  g1(18,24)=1;
end
if nargout >= 3,
  %
  % Hessian matrix
  %

  g2 = sparse([],[],[],18,1156);
end
if nargout >= 4,
  %
  % Third order derivatives
  %

  g3 = sparse([],[],[],18,39304);
end
end
